home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvi2ps / dvi-to-ps / tex.ps < prev   
Text File  |  1990-10-01  |  13KB  |  386 lines

  1. %!              for use by dvi2ps Version 2.00
  2. % $Header: tex.ps,v 2.0 88/06/07 15:12:32 peterd Rel2 $
  3. % a start (Ha!) at a TeX mode for PostScript.
  4. % The following defines procedures assumed and used by program "dvi2ps"
  5. % and must be downloaded or sent as a header file for all TeX jobs.
  6.  
  7. % By:  Neal Holtz, Carleton University, Ottawa, Canada
  8. %      <holtz@cascade.carleton.cdn>
  9. %      <holtz%cascade.carleton.cdn@ubc.csnet>
  10. %      June, 1985
  11. %      Last Modified: Aug 25/85
  12. % oystr 12-Feb-1986
  13. %   Changed @dc macro to check for a badly formed bits in character
  14. %   definitions.  Can get a <> bit map if a character is not actually
  15. %   in the font file.  This is absolutely guaranteed to drive the
  16. %   printer nuts - it will appear that you can no longer define a
  17. %   new font, although the built-ins will still be there.
  18. % mackay 4-Jan-1988
  19. %   Changed size of character array to reflect gf usage (256 characters)
  20.  
  21. % To convert this file into a downloaded file instead of a header
  22. % file, uncomment all of the lines beginning with %-%
  23.  
  24. %-%0000000             % Server loop exit password
  25. %-%serverdict begin exitserver
  26. %-%  systemdict /statusdict known
  27. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  28. %-% if
  29.  
  30. /TeXDict 200 dict def   % define a working dictionary
  31. TeXDict begin           % start using it.
  32.  
  33.                         % units are in "dots" (300/inch)
  34. /Resolution 300 def
  35. /Inch  {Resolution mul} def  % converts inches to internal units
  36.  
  37. /Mtrx 6 array def
  38.  
  39. %%%%%%%%%%%%%%%%%%%%% Page setup (user) options %%%%%%%%%%%%%%%%%%%%%%%%
  40.  
  41. % dvi2ps will output coordinates in the TeX system ([0,0] 1" down and in
  42. % from top left, with y +ive downward).  The default PostScript system
  43. % is [0,0] at bottom left, y +ive up.  The Many Matrix Machinations in
  44. % the following code are an attempt to reconcile that. The intent is to
  45. % specify the scaling as 1 and have only translations in the matrix to
  46. % properly position the text.  Caution: the default device matrices are
  47. % *not* the same in all PostScript devices; that should not matter in most 
  48. % of the code below (except for lanscape mode -- in that, rotations of
  49. % -90 degrees resulted in the the rotation matrix [ e 1 ]
  50. %                                                 [ 1 e ]
  51. % where the "e"s were almost exactly but not quite unlike zeros.
  52.  
  53. /@letter
  54.   { letter initmatrix
  55.     72 Resolution div dup neg scale          % set scaling to 1.
  56.     310 -3005 translate      % move origin to top (these are not exactly 1"
  57.     Mtrx currentmatrix pop   % and -10" because margins aren't set exactly right)
  58.   } def
  59.         % note mode is like letter, except it uses less VM
  60. /@note
  61.   { note initmatrix
  62.     72 Resolution div dup neg scale          % set scaling to 1.
  63.     310 -3005 translate                      % move origin to top
  64.     Mtrx currentmatrix pop
  65.   } def
  66.  
  67. /@landscape
  68.   { letter initmatrix
  69.     72 Resolution div dup neg scale          % set scaling to 1.
  70. %    -90 rotate                              % it would be nice to be able to do this
  71.     Mtrx currentmatrix 0 0.0 put             % but instead we have to do things like this because what
  72.     Mtrx 1 -1.0 put                          % should be zero terms aren't (and text comes out wobbly)
  73.     Mtrx 2 1.0 put                           % Fie!  This likely will not work on QMS printers
  74.     Mtrx 3 0.0 put                           % (nor on others where the device matrix is not like
  75.     Mtrx  setmatrix                          %  like it is on the LaserWriter).
  76.     300 310  translate                       % move origin to top
  77.     Mtrx currentmatrix pop
  78.   } def
  79.  
  80. /@legal
  81.   { legal initmatrix
  82.     72 Resolution div dup neg scale          % set scaling to 1.
  83.     295 -3880 translate                      % move origin to top
  84.     Mtrx currentmatrix pop
  85.   } def
  86.  
  87. /@manualfeed
  88.    { statusdict /manualfeed true put
  89.      statusdict /manualfeedtimeout 300 put  % 5 minutes
  90.    } def
  91.         % n @copies -   set number of copies
  92. /@copies
  93.    { /#copies exch def
  94.    } def
  95.  
  96. %%%%%%%%%%%%%%%%%%%% Procedure Defintions %%%%%%%%%%%%%%%%%%%%%%%%%%
  97.  
  98. /@newfont       % id @newfont -         -- initialize a new font dictionary
  99.   { /newname exch def
  100.     pop
  101.     newname 7 dict def          % allocate new font dictionary
  102.     newname load begin
  103.         /FontType 3 def
  104.         /FontMatrix [1 0 0 -1 0 0] def
  105.         /FontBBox [0 0 1 1] def
  106. % mackay 4-Jan-1987 changed size of array from 128 to 256 for gf fonts
  107.         /BitMaps 256 array def
  108.         /BuildChar {CharBuilder} def
  109.         /Encoding 256 array def
  110.         0 1 255 {Encoding exch /.undef put} for
  111.         end
  112.     newname newname load definefont pop
  113.   } def
  114.  
  115.  
  116. % the following is the only character builder we need.  it looks up the
  117. % char data in the BitMaps array, and paints the character if possible.
  118. % char data  -- a bitmap descriptor -- is an array of length 6, of 
  119. %          which the various slots are:
  120.  
  121. /ch-image {ch-data 0 get} def   % the hex string image
  122. /ch-width {ch-data 1 get} def   % the number of pixels across
  123. /ch-height {ch-data 2 get} def  % the number of pixels tall
  124. /ch-xoff  {ch-data 3 get} def   % number of pixels below origin
  125. /ch-yoff  {ch-data 4 get} def   % number of pixels to left of origin
  126. /ch-tfmw  {ch-data 5 get} def   % spacing to next character
  127.  
  128. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  129.   { /ch-code exch def           % save the char code
  130.     /font-dict exch def         % and the font dict.
  131.     /ch-data font-dict /BitMaps get ch-code get def     % get the bitmap descriptor for char
  132.     ch-data null eq not
  133.       { ch-tfmw   0   ch-xoff neg   ch-yoff neg   ch-width ch-xoff sub   ch-height ch-yoff sub
  134.             setcachedevice
  135.         ch-width ch-height true [1 0  0 1  ch-xoff ch-yoff]
  136.             {ch-image} imagemask
  137.       }
  138.     if
  139.   } def
  140.  
  141.  
  142. /@sf            % fontdict @sf -        -- make that the current font
  143.   { setfont() pop
  144.   } def
  145.  
  146.                 % in the following, the font-cacheing mechanism requires that
  147.                 % a name unique in the particular font be generated
  148.  
  149. /@dc            % char-data ch @dc -    -- define a new character bitmap in current font
  150.   { /ch-code exch def
  151. % ++oystr 12-Feb-86++
  152.     dup 0 get
  153.     length 2 lt
  154.       { pop [ <00> 1 1 0 0 8.00 ] } % replace <> with null
  155.     if
  156. % --oystr 12-Feb-86--
  157.     /ch-data exch def
  158.     currentfont /BitMaps get ch-code ch-data put
  159.     currentfont /Encoding get ch-code 
  160.        dup (   ) cvs cvn   % generate a unique name simply from the character code
  161.        put
  162.   } def
  163.  
  164. /@bop0           % n @bop0 -              -- begin the char def section of a new page
  165.   { 
  166.   } def
  167.  
  168. /@bop1           % n @bop1 -              -- begin a brand new page
  169.   { pop
  170.     erasepage initgraphics 
  171.     Mtrx setmatrix
  172.     /SaveImage save def() pop
  173.   } def
  174.  
  175. %--  tjh sept. 87: if this page has a mac drawing on it, we have to
  176. %--  use showpage in the md dictionary.
  177. /@eop           % - @eop -              -- end a page
  178.   {
  179.     userdict /md known {
  180.     userdict /md get type /dicttype eq {
  181.         md /MacDrwgs known {
  182.         md begin showpage end
  183.         }{
  184.         showpage
  185.         } ifelse
  186.     }{
  187.         showpage
  188.     } ifelse
  189.     }{
  190.     showpage
  191.     } ifelse
  192.     SaveImage restore() pop
  193.   } def
  194.  
  195. /@start         % - @start -            -- start everything
  196.   { @letter                             % (there is not much to do)
  197.   } def
  198.  
  199. /@end           % - @end -              -- done the whole shebang
  200.   { end
  201.   } def
  202.  
  203. /p              % x y p -               -- move to position
  204.   { moveto
  205.   } def
  206.  
  207. /r              % x r -                 -- move right
  208.   { 0 rmoveto
  209.   } def
  210.  
  211. /s              % string s -            -- show the string
  212.   { show
  213.   } def
  214.  
  215. /c              % ch c -                -- show the character (code given)
  216.   { c-string exch 0 exch put
  217.     c-string show
  218.   } def
  219.  
  220. /c-string ( ) def
  221.  
  222. /ru             % dx dy ru -   -- set a rule (rectangle)
  223.   { /dy exch neg def    % because dy is height up from bottom
  224.     /dx exch def
  225.     /x currentpoint /y exch def def   % remember current point
  226.     newpath x y moveto
  227.     dx 0 rlineto
  228.     0 dy rlineto
  229.     dx neg 0 rlineto
  230.     closepath fill
  231.     x y moveto
  232.   } def
  233.  
  234. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  235. %%     the \special command junk
  236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  237. %   The structure of the PostScript produced by dvi2ps for \special is:
  238. %         @beginspecial
  239. %           - any number of @hsize, @hoffset, @hscale, etc., commands
  240. %         @setspecial
  241. %           - the users file of PostScript commands
  242. %         @endspecial
  243.  
  244. % The @beginspecial command recognizes whether the Macintosh Laserprep
  245. % has been loaded or not, and redfines some Mac commands if so.
  246. % The @setspecial handles the users shifting, scaling, clipping commands
  247.  
  248. %-- tjh sept. 87: made changes to allow postscript and macdrawing to
  249. %-- to be inserted with version 65 of the md dictionary.  Many bugs
  250. %-- were fixed:
  251. %--    vo changed to vof, name conflict with md
  252. %--    vs changed to vsz, name conflict with md
  253. %--    substantially changed @setspecial and @MacSetUp
  254. %-- Also, made changes to allow users to specify offsets
  255. %-- and clip rectangles in inches.
  256.  
  257. % The following are user settable options from the \special command.
  258.  
  259. /@SpecialDefaults
  260.   { /hs 8.5 72 mul def
  261.     /vsz 11 72 mul def
  262.     /ho 0 def
  263.     /vof 0 def
  264.     /hsc 1 def
  265.     /vsc 1 def
  266.     /CLIP false def
  267.   } def
  268.  
  269. %       d @hsize -      specify a horizontal clipping dimension
  270. %                       these 2 are executed before the MacDraw initializations
  271. /@hsize {72 mul /hs exch def /CLIP true def} def
  272. /@vsize {72 mul /vsz exch def /CLIP true def} def
  273.  
  274. %       d @hoffset -    specify a shift for the drwgs
  275. /@hoffset {72 mul /ho exch def} def
  276. /@voffset {72 mul /vof exch def} def
  277.  
  278. %       s @hscale -     set scale factor
  279. /@hscale {/hsc exch def} def
  280. /@vscale {/vsc exch def} def
  281.  
  282. /@setclipper
  283.   { hsc vsc scale
  284.     CLIP
  285.       { newpath 0 0 moveto hs 0 rlineto 0 vsz rlineto hs neg 0 rlineto closepath clip }
  286.     if
  287.   } def
  288.  
  289. % this will be invoked as the result of a \special command (for the
  290. % inclusion of PostScript graphics).  The basic idea is to change all
  291. % scaling and graphics back to defaults, but to shift the origin
  292. % to the current position on the page.  Due to TeXnical difficulties,
  293. % we only set the y-origin.  The x-origin is set at the left edge of
  294. % the page.
  295.  
  296. /@beginspecial
  297.   { gsave /SpecialSave save def
  298.           % the following magic incantation establishes the current point as
  299.           % the users origin, and reverts back to default scalings, rotations
  300.     currentpoint transform initgraphics itransform translate
  301.     @SpecialDefaults    % setup default offsets, scales, sizes
  302.     @MacSetUp           % fix up Mac stuff 
  303.   } def
  304.  
  305.  
  306. %--  tjh: assume this is raw postscript, but save some state in case its not.
  307. /@setspecial
  308.   {
  309.     /specmtrx matrix currentmatrix def
  310.     ho vof translate @setclipper
  311.   } def
  312.  
  313.  
  314. /@endspecial
  315.   { SpecialSave restore
  316.     grestore
  317.   } def
  318.  
  319.  
  320. % - @MacSetUp -   turn-off/fix-up all the MacDraw stuff that might hurt us
  321.                 % we depend on 'psu' being the first procedure executed
  322.                 % by a Mac document.  We redefine 'psu' to adjust page
  323.                 % translations, and to do all other the fixups required.
  324.                 % This stuff will not harm other included PS files
  325. /@MacSetUp
  326.   { userdict /md known  % if md is defined
  327.       { userdict /md get type /dicttype eq      % and if it is a dictionary
  328.          {
  329.            md begin                             % then redefine some stuff
  330.               /psu                              % redfine psu to set origins, etc.
  331.                 /psu load
  332.                         % this procedure contains almost all the fixup code
  333.                 {
  334. %          /letter {} def    % it is bad manners to execute the real
  335. %          /note {} def      %  versions of these (clears page image, etc.)
  336. %          /legal {} def
  337.           /MacDrwgs true def
  338.           specmtrx setmatrix % restore pre-@setspecial state.
  339.           initclip         % ditto
  340.           % change smalls to prevent page clearing.
  341.           /smalls [ lnop lnop lnop lnop lnop lnop lnop lnop lnop ] def
  342.           0 0 0 0 ppr astore pop  % prevents origin translation.
  343.           % redifine cp, do the showpage later, see @eop
  344.                   /cp {
  345.             pop
  346.             pop
  347.             pm restore
  348.           } def              % no printing of pages
  349.                 }
  350.                 concatprocs 
  351.               def
  352.               /od
  353.         % redefine od to translate and scale.
  354.         % redfine load to set clipping region.
  355.                 /od load
  356.                 {
  357.           ho vof translate
  358.           hsc vsc scale
  359.           CLIP {
  360.               /nc
  361.             /nc load
  362.             { newpath 0 0 moveto hs 0 rlineto 0 vsz rlineto
  363.             hs neg 0 rlineto closepath clip }
  364.             concatprocs
  365.               def
  366.           } if
  367.         }
  368.                 concatprocs
  369.               def
  370.            end }
  371.         if }
  372.     if    
  373.   } def
  374.  
  375. %       p1 p2 concatprocs p       - concatenate procedures
  376. /concatprocs
  377.   { /p2 exch cvlit def 
  378.     /p1 exch cvlit def
  379.     /p p1 length p2 length add array def
  380.     p 0 p1 putinterval 
  381.     p p1 length p2 putinterval
  382.     p cvx
  383.   } def
  384.  
  385. end                     % revert to previous dictionary
  386.